package com.xpgk.mvc.collection.binShopService;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang.StringUtils;

import com.jfinal.aop.Before;
import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.jfinal.render.Render;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.bentryRegister.Customer;
import com.xpgk.mvc.bentryRegister.CustomerDetail;
import com.xpgk.mvc.bentryRegister.CustomerProduct;
import com.xpgk.mvc.binShopService.BeingServedController;
import com.xpgk.mvc.binShopService.BinShopServiceService;
import com.xpgk.mvc.binShopService.CustomerService;
import com.xpgk.mvc.binShopService.CustomerServiceMonthNurse;
import com.xpgk.mvc.binShopService.CustomerServiceNurse;
import com.xpgk.mvc.binShopService.ServiceShaping;
import com.xpgk.mvc.codeSet.Code;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.mvc.productOrgExperience.ProductOrgExperience;
import com.xpgk.mvc.productOutin.ProductOutin;
import com.xpgk.mvc.productSet.Product;
import com.xpgk.mvc.productStock.ProductStock;
import com.xpgk.mvc.productStock.ProductStockInfo;
import com.xpgk.mvc.statistic.dailyTotalStatistic.DailyNursingTotal;
import com.xpgk.mvc.statistic.monthTotalStatistic.MonthTotal;
import com.xpgk.mvc.statistic.yearTotalStatistic.YearTotal;
import com.xpgk.mvc.user.User;
import com.xpgk.tools.ToolDateTime;
import com.xpgk.tools.ToolRandoms;

public class BinShopOutController extends BaseController{
	BinShopOutService binShopOutService;
	private BinShopColServiceService binShopColServiceService;
	private BinShopServiceService binShopServiceService;
	@SuppressWarnings("unused")
	private static final Log log = Log.getLog(BinShopOutController.class);
	public void index(){
		String sqlbb = "SELECT * FROM sb_product_orgexperience where organIds =? and bbExperience IS NOT NULL and dataStatus = '1'";
		String sqlkb = "SELECT * FROM sb_product_orgexperience where organIds =? and kbExperience IS NOT NULL and dataStatus = '1'";
		String sqlfr = "SELECT * FROM sb_product_orgexperience where organIds =? and frExperience IS NOT NULL and dataStatus = '1'";
		ProductOrgExperience bb = ProductOrgExperience.dao.findFirst(sqlbb,getCUserOrganIds());
		int n = 4;
		if(bb!=null){
			n++;
			setAttr("bbExp", "1");
		}else{
			setAttr("bbExp", "0");
		}
		ProductOrgExperience kb = ProductOrgExperience.dao.findFirst(sqlkb,getCUserOrganIds());
		if(kb!=null){
			n++;
			setAttr("kbExp", "1");
		}else{
			setAttr("kbExp", "0");
		}
		ProductOrgExperience fr = ProductOrgExperience.dao.findFirst(sqlfr,getCUserOrganIds());
		if(fr!=null){
			n = n+2;
			setAttr("Exp", "1");
		}else{
			setAttr("Exp", "0");
		}
		setAttr("partnum",n);
		setAttr("organids", getCUserOrganIds());
		String serviceIds = ToolRandoms.getUuid(true);
		
		setAttr("serviceIds",serviceIds);
		render("/collection/binShopService/BinShopServiceOut.html");
	}
	/**
	 * 根据会员编号,手机号,姓名查出会员信息
	 * 
	 */
	public void getCusByHybh() {
		String hybh = getPara("hybh");
		String name = getPara("name");
		String phone = getPara("phone");
		String gxsj = getPara("starttime");
		gxsj = gxsj.substring(0,10);
		// 获取当前登录机构id
		String orgid = getCUserOrganIds();
		Map<String, Object> mm = binShopOutService.getCusByHybh(hybh, name, phone, orgid);
		Record  cd =(Record) mm.get("customerDetail");
		Record cs = Db.findFirst("SELECT * FROM sb_customer_service WHERE date_format(startTime,'%Y-%m-%d')=?  and customerID = ? and dataStatus in(1,2)",gxsj,cd.getStr(CustomerDetail.column_customerIds));
		if(cs!=null){
			mm.put("msg", "该顾客当天已经存在服务记录，不能添加");
			
			
		
		//mm.put("customerService", cs);
		
		}
	
		renderJson(mm);
	}
	
	public void getCustomerProduct() {
		String cid = getPara("cid");
		String bw = getPara("bw");
		String date = getPara("date");
		String user = getPara("user");
		double jysy = 0;
		float jymr = 0;
		double gsy = 0;
		float gmr = 0;
		
		if (StringUtils.isNotBlank(bw) && bw.equals("yb")) {

			String orgid = getCUserOrganIds();//
			String codeId = "a07f80b6d9064a2e8357f0f87d21a115";// 瘦身

			List<Record> list = Db
					.find("SELECT ids  ,name  FROM sb_product e WHERE e.typeIds='a07f80b6d9064a2e8357f0f87d21a115'");
			if (list != null && list.size() > 0) {
				for (Record record : list) {
					if (record.getStr("name").contains("精油")) {
						setAttr("jyproductIds", record.getStr("ids"));
						List<Record> list1 = Db
								.find("SELECT SUM(IFNULL(totalExperience,0))  sy FROM sb_customer_product  WHERE  customerID = ?  AND  productID ='"
										+ record.getStr("ids") + "' ", cid);
						if (list1 != null && list1.size() > 0) {
							if(list1.get(0).get("sy")!=null){
								if(list1.get(0).get("sy")!=null){jysy = list1.get(0).get("sy");}else{jysy = 0;}
								}else{
									jysy = 0;
								}
							//setAttr("jysy", list1.get(0).get("sy"));
						}else{
							jysy = 0;
							//setAttr("jysy", 0);
						}
						list1 = Db.find("select * from sb_product_orgexperience where organIds = ? and productIds = '95e2ae17462e4d0eb1dc84bc63bc478a' and dataStatus = '1' ",orgid);
						if (list1 != null && list1.size() > 0 && list1.get(0).get("ybExperience")!=null) {
							jymr = list1.get(0).get("ybExperience");
						}else {
							list1 = Db
									.find("SELECT e.experience as  experience FROM sb_product_experience e WHERE e.partIds = '7b83623e24664b68ab46d68e5255c53f' and e.productIds='"
											+ record.getStr("ids") + "'");
							if (list1 != null && list1.size() > 0) {
								jymr = list1.get(0).get("experience");
								//setAttr("jymr", list1.get(0).get("experience"));
							}else{
								jymr = 0;
								//setAttr("jymr", 0);
							}
						}
						
					} else if (record.getStr("name").contains("膏")) {
						setAttr("gproductIds", record.getStr("ids"));
						List<Record> list1 = Db
								.find("SELECT SUM(IFNULL(totalExperience,0))  sy FROM sb_customer_product  WHERE  customerID = ?  AND  productID ='"
										+ record.getStr("ids") + "' ", cid);
						if (list1 != null && list1.size() > 0) {
							if(list1.get(0).get("sy")!=null){
								if(list1.get(0).get("sy")!=null){gsy = list1.get(0).get("sy");}else{gsy = 0;}
								}else{
									gsy = 0;
								}
							
							//setAttr("gsy", list1.get(0).get("sy"));
						}else{
							gsy = 0;
							//setAttr("gsy", 0);
						}
						list1 = Db.find("select * from sb_product_orgexperience where organIds = ? and productIds = 'daaba791f4104ae98504a1bc421e0d8d' and dataStatus = '1' ",orgid);
						if (list1 != null && list1.size() > 0 && list1.get(0).get("ybExperience")!=null) {
						
							gmr = list1.get(0).get("ybExperience");
						}else {
						list1 = Db
								.find("SELECT e.experience as  experience  FROM sb_product_experience e WHERE e.partIds = '7b83623e24664b68ab46d68e5255c53f' and e.productIds='"
										+ record.getStr("ids") + "'");
						if (list1 != null && list1.size() > 0) {
							gmr = list1.get(0).get("experience");
							//setAttr("gmr", list1.get(0).get("experience"));
						}else{
							gmr = 0;
							//setAttr("gmr", 0);
						}}
					}

				}

			}

		}

		if (StringUtils.isNotBlank(bw) && bw.equals("dt")) {

			String orgid = getCUserOrganIds();//
			String codeId = "a07f80b6d9064a2e8357f0f87d21a115";// 瘦身

			List<Record> list = Db
					.find("SELECT ids  ,name  FROM sb_product e WHERE e.typeIds='a07f80b6d9064a2e8357f0f87d21a115'");
			if (list != null && list.size() > 0) {
				for (Record record : list) {
					if (record.getStr("name").contains("精油")) {
						setAttr("jyproductIds", record.getStr("ids"));
						List<Record> list1 = Db
								.find("SELECT SUM(IFNULL(totalExperience,0))  sy FROM sb_customer_product  WHERE  customerID = ?  AND  productID ='"
										+ record.getStr("ids") + "' ", cid);
						if (list1 != null && list1.size() > 0) {
							if(list1.get(0).get("sy")!=null){jysy = list1.get(0).get("sy");}else{jysy = 0;}
							//setAttr("jysy", list1.get(0).get("sy"));
						}else{
							jysy = 0;
							//setAttr("jysy", 0);
						}
						list1 = Db.find("select * from sb_product_orgexperience where organIds = ? and productIds = '95e2ae17462e4d0eb1dc84bc63bc478a' and dataStatus = '1' ",orgid);
						if (list1 != null && list1.size() > 0 && list1.get(0).get("dtExperience")!=null) {
							jymr = list1.get(0).get("dtExperience");
						}else {
						list1 = Db
								.find("SELECT e.experience as  experience FROM sb_product_experience e WHERE e.partIds = 'e41f214dc9a04bc691b5674f39de0902' and e.productIds='"+ record.getStr("ids") + "'");
						if (list1 != null && list1.size() > 0) {
							jymr = list1.get(0).get("experience");
							//setAttr("jymr", list1.get(0).get("experience"));
						}else{
							jymr = 0;
							//setAttr("jymr", 0);
						}
						}
					} else if (record.getStr("name").contains("膏")) {
						setAttr("gproductIds", record.getStr("ids"));
						List<Record> list1 = Db
								.find("SELECT SUM(IFNULL(totalExperience,0))  sy FROM sb_customer_product  WHERE  customerID = ?  AND  productID ='"
										+ record.getStr("ids") + "' ", cid);
						if (list1 != null && list1.size() > 0) {
							if(list1.get(0).get("sy")!=null){gsy = list1.get(0).get("sy");}else{gsy = 0;}
							//setAttr("gsy", list1.get(0).get("sy"));
						}else{
							gsy = 0;
							//setAttr("gsy", 0);
						}
						list1 = Db.find("select * from sb_product_orgexperience where organIds = ? and productIds = 'daaba791f4104ae98504a1bc421e0d8d' and dataStatus = '1' ",orgid);
						if (list1 != null && list1.size() > 0 && list1.get(0).get("dtExperience")!=null) {
							gmr = list1.get(0).get("dtExperience");
						}else {
						list1 = Db
								.find("SELECT e.experience as  experience  FROM sb_product_experience e WHERE e.partIds = 'e41f214dc9a04bc691b5674f39de0902' and e.productIds='"
										+ record.getStr("ids") + "' ");
						if (list1.get(0).get("experience") != null) {
							gmr =  list1.get(0).get("experience");
							//setAttr("gmr", list1.get(0).get("experience"));
						}else{
							gmr = 0;
							//setAttr("gmr", 0);
						}
						}
					}

				}

			}

		}

		if (StringUtils.isNotBlank(bw) && bw.equals("xt")) {

			String orgid = getCUserOrganIds();//
			String codeId = "a07f80b6d9064a2e8357f0f87d21a115";// 瘦身

			List<Record> list = Db
					.find("SELECT ids  ,name  FROM sb_product e WHERE e.typeIds='a07f80b6d9064a2e8357f0f87d21a115'");
			if (list != null && list.size() > 0) {
				for (Record record : list) {
					if (record.getStr("name").contains("精油")) {
						setAttr("jyproductIds", record.getStr("ids"));
						List<Record> list1 = Db
								.find("SELECT SUM(IFNULL(totalExperience,0))  sy FROM sb_customer_product  WHERE  customerID = ?  AND  productID ='"
										+ record.getStr("ids") + "' ", cid);
						if (list1 != null && list1.size() > 0) {
							if(list1.get(0).get("sy")!=null){jysy = list1.get(0).get("sy");}else{jysy = 0;}
							//setAttr("jysy", list1.get(0).get("sy"));
						}else{
							jysy = 0;
							//setAttr("jysy", 0);
						}
						list1 = Db.find("select * from sb_product_orgexperience where organIds = ? and productIds = '95e2ae17462e4d0eb1dc84bc63bc478a' and dataStatus = '1' ",orgid);
						if (list1 != null && list1.size() > 0 && list1.get(0).get("xtExperience")!=null) {
							jymr = list1.get(0).get("xtExperience");
						}else {
						list1 = Db
								.find("SELECT e.experience as  experience FROM sb_product_experience e WHERE e.partIds = '3d2a59dd84504ff2841e0ebcc1fa339f' and e.productIds='"
										+ record.getStr("ids") + "' ");
						if (list1 != null && list1.size() > 0) {
							jymr = list1.get(0).get("experience");
							//setAttr("jymr", list1.get(0).get("experience"));
						}else{
							jymr = 0;
							//setAttr("jymr", 0);
						}
						}
					} else if (record.getStr("name").contains("膏")) {
						setAttr("gproductIds", record.getStr("ids"));
						List<Record> list1 = Db
								.find("SELECT SUM(IFNULL(totalExperience,0))  sy FROM sb_customer_product  WHERE  customerID = ?  AND  productID ='"
										+ record.getStr("ids") + "' ", cid);
						if (list1 != null && list1.size() > 0) {
							if(list1.get(0).get("sy")!=null){gsy = list1.get(0).get("sy");}else{gsy = 0;}
							//setAttr("gsy", list1.get(0).get("sy"));
						}else{
							gsy = 0;
							//setAttr("gsy", 0);
						}
						list1 = Db.find("select * from sb_product_orgexperience where organIds = ? and productIds = 'daaba791f4104ae98504a1bc421e0d8d' and dataStatus = '1' ",orgid);
						if (list1 != null && list1.size() > 0 && list1.get(0).get("xtExperience")!=null) {
							gmr = list1.get(0).get("xtExperience");
						}else {
						list1 = Db
								.find("SELECT e.experience as  experience  FROM sb_product_experience e WHERE e.partIds = '3d2a59dd84504ff2841e0ebcc1fa339f' and e.productIds='"
										+ record.getStr("ids") + "'  ");
						if (list1 != null && list1.size() > 0) {
							gmr = list1.get(0).get("experience");
							//setAttr("gmr", list1.get(0).get("experience"));
						}else{
							gmr = 0;
							//setAttr("gmr", 0);
						}
						}
					}

				}

			}

		}

		if (StringUtils.isNotBlank(bw) && bw.equals("gb")) {

			String orgid = getCUserOrganIds();//
			String codeId = "a07f80b6d9064a2e8357f0f87d21a115";// 瘦身

			List<Record> list = Db
					.find("SELECT ids  ,name  FROM sb_product e WHERE e.typeIds='a07f80b6d9064a2e8357f0f87d21a115'");
			if (list != null && list.size() > 0) {
				for (Record record : list) {
					if (record.getStr("name").contains("精油")) {
						setAttr("jyproductIds", record.getStr("ids"));
						List<Record> list1 = Db.find("SELECT SUM(IFNULL(totalExperience,0))  sy FROM sb_customer_product  WHERE  customerID = ?  AND  productID ='"	+ record.getStr("ids") + "' ", cid);
						if (list1 != null && list1.size() > 0) {
							if(list1.get(0).get("sy")!=null){jysy = list1.get(0).get("sy");}else{jysy = 0;}
							//setAttr("jysy", list1.get(0).get("sy"));
						}else{
							jysy = 0;
							//setAttr("jysy", 0);
						}
						list1 = Db.find("select * from sb_product_orgexperience where organIds = ? and productIds = '95e2ae17462e4d0eb1dc84bc63bc478a' and dataStatus = '1' ",orgid);
						if (list1 != null && list1.size() > 0 && list1.get(0).get("gbExperience")!=null) {
							jymr = list1.get(0).get("gbExperience");
						}else {
						list1 = Db.find("SELECT e.experience as  experience FROM sb_product_experience e WHERE e.partIds = '92b836d30f494b8388c84a0175839f70' and e.productIds='"
										+ record.getStr("ids") + "'  ");
						if (list1 != null && list1.size() > 0) {
							jymr = list1.get(0).get("experience");
							//setAttr("jymr", list1.get(0).get("experience"));
						}else{
							jymr = 0;
							//setAttr("jymr", 0);
						}
						}
					} else if (record.getStr("name").contains("膏")) {
						setAttr("gproductIds", record.getStr("ids"));
						List<Record> list1 = Db.find("SELECT SUM(IFNULL(totalExperience,0))  sy FROM sb_customer_product  WHERE  customerID = ?  AND  productID ='"+ record.getStr("ids") + "' ", cid);
						if (list1 != null && list1.size() > 0) {
							if(list1.get(0).get("sy")!=null){gsy = list1.get(0).get("sy");}else{gsy = 0;}
							//setAttr("gsy", list1.get(0).get("sy"));
						}else{
							gsy = 0;
							//setAttr("gsy", 0);
						}
						list1 = Db.find("select * from sb_product_orgexperience where organIds = ? and productIds = 'daaba791f4104ae98504a1bc421e0d8d' and dataStatus = '1' ",orgid);
						if (list1 != null && list1.size() > 0 && list1.get(0).get("gbExperience")!=null) {
							gmr = list1.get(0).get("gbExperience");
						}else {
						list1 = Db.find("SELECT e.experience as  experience  FROM sb_product_experience e WHERE e.partIds = '92b836d30f494b8388c84a0175839f70' and e.productIds='"
										+ record.getStr("ids") + "'  ");
						if (list1 != null && list1.size() > 0) {
							gmr =  list1.get(0).get("experience");
							//setAttr("gmr", list1.get(0).get("experience"));
						}else{
							gmr = 0;
							//setAttr("gmr", 0);
						}
						}
					}

				}

			}

		}
		
		//---------------------------------

		if (StringUtils.isNotBlank(bw) && bw.equals("bb")) {

			String orgid = getCUserOrganIds();//
			String codeId = "a07f80b6d9064a2e8357f0f87d21a115";// 瘦身

			List<Record> list = Db
					.find("SELECT ids  ,name  FROM sb_product e WHERE e.typeIds='a07f80b6d9064a2e8357f0f87d21a115'");
			if (list != null && list.size() > 0) {
				for (Record record : list) {
					if (record.getStr("name").contains("精油")) {
						setAttr("jyproductIds", record.getStr("ids"));
						List<Record> list1 = Db.find("SELECT SUM(IFNULL(totalExperience,0))  sy FROM sb_customer_product  WHERE  customerID = ?  AND  productID ='"	+ record.getStr("ids") + "' ", cid);
						if (list1 != null && list1.size() > 0) {
							if(list1.get(0).get("sy")!=null){jysy = list1.get(0).get("sy");}else{jysy = 0;}
							//setAttr("jysy", list1.get(0).get("sy"));
						}else{
							jysy = 0;
							//setAttr("jysy", 0);
						}
						list1 = Db.find("select * from sb_product_orgexperience where organIds = ? and productIds = '95e2ae17462e4d0eb1dc84bc63bc478a' and dataStatus = '1' ",orgid);
						if (list1 != null && list1.size() > 0) {
						if(list1.get(0).get("bbExperience")!=null){
							jymr = list1.get(0).get("bbExperience");
						}}else {
						
							jymr = 0;
							//setAttr("jymr", 0);
						
						}
					} else if (record.getStr("name").contains("膏")) {
						setAttr("gproductIds", record.getStr("ids"));
						List<Record> list1 = Db.find("SELECT SUM(IFNULL(totalExperience,0))  sy FROM sb_customer_product  WHERE  customerID = ?  AND  productID ='"+ record.getStr("ids") + "' ", cid);
						if (list1 != null && list1.size() > 0) {
							if(list1.get(0).get("sy")!=null){gsy = list1.get(0).get("sy");}else{gsy = 0;}
							//setAttr("gsy", list1.get(0).get("sy"));
						}else{
							gsy = 0;
							//setAttr("gsy", 0);
						}
						list1 = Db.find("select * from sb_product_orgexperience where organIds = ? and productIds = 'daaba791f4104ae98504a1bc421e0d8d' and dataStatus = '1' ",orgid);
						if (list1 != null && list1.size() > 0) {
						if(list1.get(0).get("bbExperience")!=null){
							gmr = list1.get(0).get("bbExperience");
						}}else {
						
							gmr = 0;
							//setAttr("gmr", 0);
						
						}
					}

				}

			}

		}
		
		
		

		if (StringUtils.isNotBlank(bw) && bw.equals("kb")) {

			String orgid = getCUserOrganIds();//
			String codeId = "a07f80b6d9064a2e8357f0f87d21a115";// 瘦身

			List<Record> list = Db
					.find("SELECT ids  ,name  FROM sb_product e WHERE e.typeIds='a07f80b6d9064a2e8357f0f87d21a115'");
			if (list != null && list.size() > 0) {
				for (Record record : list) {
					if (record.getStr("name").contains("精油")) {
						setAttr("jyproductIds", record.getStr("ids"));
						List<Record> list1 = Db.find("SELECT SUM(IFNULL(totalExperience,0))  sy FROM sb_customer_product  WHERE  customerID = ?  AND  productID ='"	+ record.getStr("ids") + "' ", cid);
						if (list1 != null && list1.size() > 0) {
							if(list1.get(0).get("sy")!=null){jysy = list1.get(0).get("sy");}else{jysy = 0;}
							//setAttr("jysy", list1.get(0).get("sy"));
						}else{
							jysy = 0;
							//setAttr("jysy", 0);
						}
						list1 = Db.find("select * from sb_product_orgexperience where organIds = ? and productIds = '95e2ae17462e4d0eb1dc84bc63bc478a' and dataStatus = '1' ",orgid);
						if (list1 != null && list1.size() > 0) {
						if(list1.get(0).get("kbExperience")!=null){
							jymr = list1.get(0).get("kbExperience");
						}}else {
						
							jymr = 0;
							//setAttr("jymr", 0);
						
						}
					} else if (record.getStr("name").contains("膏")) {
						setAttr("gproductIds", record.getStr("ids"));
						List<Record> list1 = Db.find("SELECT SUM(IFNULL(totalExperience,0))  sy FROM sb_customer_product  WHERE  customerID = ?  AND  productID ='"+ record.getStr("ids") + "' ", cid);
						if (list1 != null && list1.size() > 0) {
							if(list1.get(0).get("sy")!=null){gsy = list1.get(0).get("sy");}else{gsy = 0;}
							//setAttr("gsy", list1.get(0).get("sy"));
						}else{
							gsy = 0;
							//setAttr("gsy", 0);
						}
						list1 = Db.find("select * from sb_product_orgexperience where organIds = ? and productIds = 'daaba791f4104ae98504a1bc421e0d8d' and dataStatus = '1' ",orgid);
						if (list1 != null && list1.size() > 0) {
						if(list1.get(0).get("kbExperience")!=null){
							gmr = list1.get(0).get("kbExperience");
						}}else {
						
							gmr = 0;
							//setAttr("gmr", 0);
						
						}
					}

				}

			}

		}
		
		

		if (StringUtils.isNotBlank(bw) && bw.equals("zfr")||StringUtils.isNotBlank(bw) && bw.equals("yfr")) {

			String orgid = getCUserOrganIds();//
			String codeId = "a07f80b6d9064a2e8357f0f87d21a115";// 瘦身

			List<Record> list = Db
					.find("SELECT ids  ,name  FROM sb_product e WHERE e.typeIds='a07f80b6d9064a2e8357f0f87d21a115'");
			if (list != null && list.size() > 0) {
				for (Record record : list) {
					if (record.getStr("name").contains("精油")) {
						setAttr("jyproductIds", record.getStr("ids"));
						List<Record> list1 = Db.find("SELECT SUM(IFNULL(totalExperience,0))  sy FROM sb_customer_product  WHERE  customerID = ?  AND  productID ='"	+ record.getStr("ids") + "' ", cid);
						if (list1 != null && list1.size() > 0) {
							if(list1.get(0).get("sy")!=null){jysy = list1.get(0).get("sy");}else{jysy = 0;}
							//setAttr("jysy", list1.get(0).get("sy"));
						}else{
							jysy = 0;
							//setAttr("jysy", 0);
						}
						list1 = Db.find("select * from sb_product_orgexperience where organIds = ? and productIds = '95e2ae17462e4d0eb1dc84bc63bc478a' and dataStatus = '1' ",orgid);
						if (list1 != null && list1.size() > 0) {
						if(list1.get(0).get("frExperience")!=null){
							jymr = list1.get(0).get("frExperience");
						}}else {
						
							jymr = 0;
							//setAttr("jymr", 0);
						
						}
					} else if (record.getStr("name").contains("膏")) {
						setAttr("gproductIds", record.getStr("ids"));
						List<Record> list1 = Db.find("SELECT SUM(IFNULL(totalExperience,0))  sy FROM sb_customer_product  WHERE  customerID = ?  AND  productID ='"+ record.getStr("ids") + "' ", cid);
						if (list1 != null && list1.size() > 0) {
							if(list1.get(0).get("sy")!=null){gsy = list1.get(0).get("sy");}else{gsy = 0;}
							//setAttr("gsy", list1.get(0).get("sy"));
						}else{
							gsy = 0;
							//setAttr("gsy", 0);
						}
						list1 = Db.find("select * from sb_product_orgexperience where organIds = ? and productIds = 'daaba791f4104ae98504a1bc421e0d8d' and dataStatus = '1' ",orgid);
						if (list1 != null && list1.size() > 0) {
						if(list1.get(0).get("frExperience")!=null){
							gmr = list1.get(0).get("frExperience");
						}}else {
						
							gmr = 0;
							//setAttr("gmr", 0);
						
						}
					}

				}

			}

		}
		setAttr("jysy", jysy);
		setAttr("jymr",jymr);
		setAttr("gsy", gsy);
		setAttr("gmr", gmr);
		setAttr("user", user);
		
		setAttr("cid", cid);
		setAttr("bw", bw);
		setAttr("date", date);
		String sid = getPara("sid");
		setAttr("sid", sid);
		setAttr("mima", getPara("mima"));
		render("/collection/binShopService/customerProduct2.html");
	}
	@Before(Tx.class)
	public void updateSer() throws ParseException {
		String sf = getPara("sf");
		String bw = getPara("bw");
		String bz = getPara("bz");
		String user = getPara("user");//精护部位人员
		String dateStr = getPara("date");//带时分秒
		String endtimeStr = getPara("endtime");
		String weightStr = getPara("weight");
		String cid = getPara("cid");
		String sid = getPara("sid");
		String yt = getPara("yt");
//		Map<String, Object> m = binShopColServiceService.updateSer(getCUserOrganIds(), getCUserIds(),sf,bw,bz,user,dateStr,endtimeStr,
//				mima,weightStr,cid,sid,yt,jyusage,gusage,jyproductIds,gproductIds);
		
		Map<String, Object> m = new HashMap<String, Object>();
		m.put("msg",true);
		boolean isdb = false;
		boolean hasdb = false;
		String dateStr2 = dateStr.substring(0,10);
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
		Date starttime = sdf2.parse(dateStr);  
		
		Date endtime =new Date();
		if(endtimeStr!=null){
			endtime = sdf2.parse(endtimeStr);
		}
		
		float weight= 0f;
		if(weightStr!=null&&!weightStr.equals("")){
			weight = Float.parseFloat(weightStr);
			String sql = "";
		}
		String servicesql = getSqlMy(CustomerService.sqlId_selNextWeight);
		CustomerService cs0 = CustomerService.dao.findFirst(servicesql ,dateStr2,cid);
		if (cs0 != null) {
			m.put("msg","该天之后已经有服务记录，请按照时间的顺序录入服务");
			
		}else{
			
			
		
		
		//CustomerService cs = CustomerService.dao.findFirst("select *  from sb_customer_service  where DATE_FORMAT(startTime, '%Y-%m-%d')  =? and  customerID = ?",dateStr2,cid);
		//if (cs == null) {
		// 药贴 产品表 c3df895ee3b24d1193cb8156edc665b7
		//结束服务，药贴出库
		if (StringUtils.isNotBlank(yt)) {
			//判断是否用产品（精护部位）
			String shapingSql  = "SELECT * FROM sb_customer_service_shaping  WHERE  serviceIds = ? and dataStatus in ('1','2')";
			List<ServiceShaping>  ssList = ServiceShaping.dao.find(shapingSql,sid);  
			//保存服务记录
			
			CustomerDetail cdet = CustomerDetail.dao.findFirst("SELECT * FROM sb_customer_detail WHERE customerIds = ? and dataStatus in ('1','2')",cid);
			boolean isXgk = ToolDateTime.format(cdet.getDate(CustomerDetail.column_firstDate), ToolDateTime.pattern_y).equals(ToolDateTime.format(starttime, ToolDateTime.pattern_y));
			boolean isdndyXgk= ToolDateTime.format(cdet.getDate(CustomerDetail.column_firstDate), ToolDateTime.pattern_y).equals(ToolDateTime.format(starttime, ToolDateTime.pattern_y));
			CustomerService customerService = new CustomerService();
					customerService.set(CustomerService.column_ids, sid)
					.set(CustomerService.column_weight, weight)
					.set(CustomerService.column_startTime, starttime)
					.set(CustomerService.column_endTime, endtime)
					.set(CustomerService.column_organids, getCUserOrganIds())
					.set(CustomerService.column_customerID, cid)
					.set(CustomerService.column_bz, bz)
					//.set(CustomerService.column_lastWeight, customerDetail.getFloat(CustomerDetail.column_nowWeight))
					.set(CustomerService.column_plasterServier, sf)
					.set(CustomerService.column_createDate, new Date())
					.set(CustomerService.column_createId, getCUserIds())
					.set(CustomerService.column_dataStatus, 2);
					if(yt!=null&&!yt.equals("")){
						customerService.set(CustomerService.column_plasterCount,Integer.parseInt(yt));
					}
				
					if (StringUtils.isNotBlank(sf)) {
						customerService.set(CustomerService.column_isPlaster, "1");
					}
					
					CustomerService lastService  = CustomerService.dao.findFirst("select weight  from sb_customer_service  where  DATE_FORMAT(startTime,'%Y-%m-%d')<? and  customerID = ? ORDER BY   startTime DESC ",dateStr2,cid);
					if(lastService!=null&&lastService.getFloat("weight")!=null){
						customerService.set(CustomerService.column_lastWeight, lastService.getFloat("weight"));
					}else{
						customerService.set(CustomerService.column_lastWeight, cdet.getFloat(CustomerDetail.column_firstWeight));
					}
					/*if (StringUtils.isNotBlank(yb) || StringUtils.isNotBlank(dt) || StringUtils.isNotBlank(xt)|| StringUtils.isNotBlank(gb)) {
						cs.set(CustomerService.column_isShaping, "1");
					}*/
					if(null != ssList && ssList.size()>0)
					{
						customerService.set(CustomerService.column_isShaping, "1");
					}
					if(!customerService.save(sid)){
						m.put("msg",false);
					}
					
					
					Float standardWeight = Float.parseFloat(cdet.getStr(CustomerDetail.column_standardWeight));
					String customerType = cdet.getStr(CustomerDetail.column_customerType);
					if(StringUtils.isNotBlank(customerType)&&customerType.equals("2")){
						hasdb = true;
					}
					if(StringUtils.isNotBlank(customerType)&&customerType.equals("0")){//减肥
						if(weight<=standardWeight){
							isdb = true;
						}
					}
					binShopColServiceService.saveTotal(getCUserOrganIds(),sdf2.parse(dateStr), isdb&& !hasdb,cid,weight,cdet,isXgk);
					if(StringUtils.isNotBlank(customerType)&&customerType.equals("2")){
						customerService.set(CustomerService.column_isGg, 1+"");
						//hasdb = true;
						if(!customerService.update()){
							m.put("msg",false);
						}
					}
					else if(StringUtils.isNotBlank(customerType)&&customerType.equals("1")){
						customerService.set(CustomerService.column_isGg, 2+"");
						if(!customerService.update()){
							m.put("msg",false);
						}
					}else{
						if(weight<=standardWeight){
							customerService.set(CustomerService.column_isGg, 1+"");
							 cdet.set(CustomerDetail.column_customerType,2+"");
							 //isdb = true;
							 if(!customerService.update()){
									m.put("msg",false);
								}
							 if(!cdet.update()){
									m.put("msg",false);
								}
							
						}else{
							cdet.set(CustomerDetail.column_customerType, "0");
							customerService.set(CustomerService.column_isGg, 0+"");
							 if(!customerService.update()){
									m.put("msg",false);
								}
							 if(!cdet.update()){
									m.put("msg",false);
								}
						}
					}
					
				
					
					
					
					/*String servicesql = getSqlMy(CustomerService.sqlId_selNextWeight);
					CustomerService cs0 = CustomerService.dao.findFirst(servicesql ,dateStr2,cid);*/
					/*if (cs0 != null) {
						cs0.set(CustomerService.column_lastWeight, weight);
						cs0.set(CustomerService.column_updateDate, new Date());
						cs0.set(CustomerService.column_updateId, getCUserIds());
						 if(!cs0.update()){
								m.put("msg",false);
							}
					}*/
					
					
					
					servicesql = getSqlMy(CustomerService.sqlId_selMinByCus);
					CustomerService cs1 = CustomerService.dao.findFirst(servicesql, cid);
					if (cs1 != null) {
						cdet.set(CustomerDetail.column_minDate, cs1.getDate(CustomerService.column_startTime));
						cdet.set(CustomerDetail.column_minWeight, cs1.getFloat(CustomerService.column_weight));
						cdet.set(CustomerDetail.column_updateDate, new Date());
						cdet.set(CustomerDetail.column_updateId, getCUserIds());
						if(!cdet.update()){
								m.put("msg",false);
							}
						
					}
					
					
					servicesql = getSqlMy(CustomerService.sqlId_selNowByCus);
					CustomerService cs2 = CustomerService.dao.findFirst(servicesql, cid);
					if (cs2 != null) {
						cdet.set(CustomerDetail.column_toStoreDate, cs2.getDate(CustomerService.column_startTime));
						cdet.set(CustomerDetail.column_nowWeight, cs2.getFloat(CustomerService.column_weight));
						cdet.set(CustomerDetail.column_updateDate, new Date());
						cdet.set(CustomerDetail.column_updateId, getCUserIds());
						if(!cdet.update()){
							m.put("msg",false);
						}
					}
					
					CustomerServiceNurse csmn = CustomerServiceNurse.dao.findFirst(" SELECT * FROM sb_customer_service_nurse WHERE customerID = ? and  YearMon = ?   LIMIT 1", cid,dateStr.substring(0, 7));
					binShopColServiceService.saveOrUpdateNurse(csmn, customerService, cdet,1,cid,1,isdndyXgk);
					CustomerServiceMonthNurse monthNurse = CustomerServiceMonthNurse.dao.findFirst("select * from sb_customer_service_month_nurse where customerIds = ? and organIds = ? and `year` = ? and dataStatus in ('1','2')",cid,getCUserOrganIds(),dateStr.substring(0,4));
					binShopServiceService.saveOrUpdateMonthNurse(monthNurse,customerService,cdet,1,getCUserIds(),2);
				
					

					
					if (Integer.parseInt(yt) > 0) {
						Product p = Product.dao.findById(Code.proYt_ids);
						String pstSql = getSqlMy(ProductStock.sqlId_selPSByOidsAndPids);
						ProductStock pst = ProductStock.dao.findFirst(pstSql, getCUserOrganIds(), p.getStr(Product.column_ids));
						if (pst != null && pst.getFloat(ProductStock.column_num) >= 1) {
							CustomerService cd = CustomerService.dao.findById(sid);
							//CustomerDetail cdet = CustomerDetail.dao.findFirst("SELECT * FROM sb_customer_detail WHERE customerIds = ?",cid);
							if (cd != null) {
								
								cd.set(CustomerService.column_plasterCount, yt);
							/*	Date date = new Date();
								Date startTime = cd.getDate(CustomerService.column_startTime);
								SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
								if(sdf.format(date).equals(sdf.format(startTime))) {  
									 cd.set(CustomerService.column_endTime, date);
								 }else{
									 cd.set(CustomerService.column_endTime, sdf.parse(sdf.format(startTime)+" 21:00:00"));
								 }*/
								
								cd.set(CustomerService.column_updateDate, new Date());
								cd.set(CustomerService.column_updateId, getCUserIds());
								m.put("msg", cd.update());
							}
							// 保存药贴出库记录
							ProductOutin po = new ProductOutin();
							po.set(ProductOutin.column_ids, ToolRandoms.getUuid(true))
									.set(ProductOutin.column_organIds, getCUserOrganIds())
									.set(ProductOutin.column_typeIds, p.getStr(Product.column_typeIds))
									.set(ProductOutin.column_productIds, p.getStr(Product.column_ids))
									.set(ProductOutin.column_number, Integer.parseInt(yt)).set(ProductOutin.column_price, 0)
									.set(ProductOutin.column_date, new Date()).set(ProductOutin.column_style, "1")
									.set(ProductOutin.column_createDate, new Date())
									.set(ProductOutin.column_createId, getCUserIds())
									.set(ProductOutin.column_userIds, getCUserIds()).set(ProductOutin.column_gxsj, new Date());
							if (!po.save()) {
								log.debug("保存" + p.getStr(Product.column_name) + "出库记录失败！！");
								throw new RuntimeException("保存" + p.getStr(Product.column_name) + "出库记录失败！！");
							}
							// 更新产品库存
							// 根据日期和机构id,产品id查出当日是否有库存记录
							String pstInsql = getSqlMy(ProductStockInfo.sqlId_selByOidsAndPidsAndTime);
							ProductStockInfo psi = ProductStockInfo.dao.findFirst(pstInsql, getCUserOrganIds(),
									p.getStr(Product.column_ids), new Date());

							float num1 = pst.getFloat(ProductStock.column_num) - Float.parseFloat(yt);
							pst.set(ProductStock.column_num, num1).set(ProductStock.column_gxsj, new Date());
							if (!pst.update()) {
								log.debug("更新产品总库存失败");
								throw new RuntimeException("更新产品总库存失败!");
							}
							if (psi != null) {
								// 库存详细信息减少库存
								float num = psi.getFloat(ProductStockInfo.column_stock) - Float.parseFloat(yt);
								psi.set(ProductStockInfo.column_stock, num).set(ProductStockInfo.column_gxsj, new Date())
										.set(ProductOutin.column_updateDate, new Date())
										.set(ProductOutin.column_updateId, getCUserIds()).update();
							} else {
								ProductStockInfo psInfo = new ProductStockInfo();
								String psinfoids = ToolRandoms.getUuid(true);
								psInfo.set(ProductStockInfo.column_ids, psinfoids)
										.set(ProductStockInfo.column_organids, getCUserOrganIds())
										.set(ProductStockInfo.column_productID, p.getStr(Product.column_ids))
										.set(ProductStockInfo.column_type, p.getStr(Product.column_typeIds))
										.set(ProductStockInfo.column_stock, pst.getFloat(ProductStock.column_num))
										.set(ProductOutin.column_createDate, new Date())
										.set(ProductOutin.column_createId, getCUserIds())
										.set(ProductStockInfo.column_gxsj, new Date());
								if (!psInfo.save()) {
									log.debug("保存产品库存记录失败！！");
									throw new RuntimeException("保存产品库存记录失败!");
								}
							}
						} else {
							log.debug(p.getStr(Product.column_name) + "库存不够，无法购买！！");
							// throw new RuntimeException(p.getStr(Product.column_name)
							// + "库存不够，请先入库！！");
							m.put("msg", p.getStr(Product.column_name) + "库存不够，请先入库！！");
						}

					}
					//保存日综合查询
					
					//保存日综合查询使用产品人数
					DailyNursingTotal  dnt = DailyNursingTotal.dao.getDnt(getCUserOrganIds(), starttime);
					
					if(null != ssList &&  ssList.size()>0)
					{
						if(dnt != null)
						{
							dnt.set(DailyNursingTotal.column_sycprs, dnt.getInt(DailyNursingTotal.column_sycprs)+1);
							if(isXgk){
								dnt.set(DailyNursingTotal.column_xgkjhrs, dnt.getInt(DailyNursingTotal.column_xgkjhrs)+1);
							}
//							double  dcbl = ((double)dnt.getInt(DailyNursingTotal.column_sycprs))/((double)dnt.getInt(DailyNursingTotal.column_sddrs));
//							dnt.set(DailyNursingTotal.column_sycprszb,new DecimalFormat("#.00").format(dcbl*100));
							if(!dnt.update())
							{
								log.debug("更新日综合查询表达标人数失败！！");
								throw new RuntimeException("更新日综合查询表达标人数失败!");
							}
						}else
						{
							dnt = new DailyNursingTotal();
							dnt.set(DailyNursingTotal.column_organids, getCUserOrganIds())
								.set(DailyNursingTotal.column_date, ToolDateTime.format(starttime, ToolDateTime.pattern_ymd))
								.set(DailyNursingTotal.column_sycprs,1);
							if(isXgk){
								dnt.set(DailyNursingTotal.column_xgkjhrs,1);
							}
//							double  dcbl = ((double)dnt.getInt(DailyNursingTotal.column_sycprs))/((double)dnt.getInt(DailyNursingTotal.column_sddrs));
//							dnt.set(DailyNursingTotal.column_sycprszb,new DecimalFormat("#.00").format(dcbl*100));
							if(!dnt.save())
							{
								log.debug("保存日综合查询表达标人数失败！！");
								throw new RuntimeException("保存日综合查询表达标人数失败!");
							}
						}
						
					
					}
					if(dnt != null)
					{
						double  dcbl = ((double)dnt.getInt(DailyNursingTotal.column_sycprs))/((double)dnt.getInt(DailyNursingTotal.column_sddrs));
						dnt.set(DailyNursingTotal.column_sycprszb,new DecimalFormat("#.00").format(dcbl*100));
						if(!dnt.update())
						{
							log.debug("更新日综合查询表达标人数失败！！");
							throw new RuntimeException("更新日综合查询表达标人数失败!");
						}
					}
					
				
					
				}
				
				//保存手法
				/*if (StringUtils.isNotBlank(sf) && sf.length() == 2) {
					User u = updateSerTool(sf ,getCUserOrganIds());
					if (u != null) {
						CustomerService cd = CustomerService.dao.findById(sid);
						if (cd != null) {
							cd.set(CustomerService.column_isPlaster, "1");
							cd.set(CustomerService.column_userID, u.get("ids"));
							cd.set(CustomerService.column_plasterServier, u.get("ids"));
							cd.set(CustomerService.column_updateDate, new Date());
							cd.set(CustomerService.column_updateId, getCUserIds());
							m.put("user", u);
							m.put("msg", cd.update());

						}
					}
				}*/
				
				
				//保存精护部位
				if (StringUtils.isNotBlank(user) && user!="-1") {
					String tsy="";
					User u = User.dao.findById(user);
					CustomerProduct cpj = CustomerProduct.dao.findFirst("SELECT *   FROM sb_customer_product  WHERE  customerID = '" + cid + "'  AND  productID ='" + getPara("jyproductIds") + "' and totalExperience >= '"+getPara("jyusage")+"'  ORDER BY totalExperience DESC LIMIT 1");
					CustomerProduct cpg = CustomerProduct.dao.findFirst("SELECT *   FROM sb_customer_product  WHERE  customerID = '" + cid + "'  AND  productID ='" + getPara("gproductIds") + "' and totalExperience >= '"+getPara("gusage")+"'   ORDER BY totalExperience DESC LIMIT 1");
					//查询顾客在当日有无产品明细存在
					/*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					CustomerProductSurplus  cpsj=CustomerProductSurplus.dao.getCustomerProductSurplus(cid,  getPara("jyproductIds"), getCUserOrganIds(), sdf.format(new Date()));
					CustomerProductSurplus  cpsg=CustomerProductSurplus.dao.getCustomerProductSurplus(cid,   getPara("gproductIds"), getCUserOrganIds(), sdf.format(new Date()));*/
					/*CustomerProductSurplus cpsj = CustomerProductSurplus.dao.findFirst("SELECT *   FROM sb_customer_product  WHERE  customerID = '" + cid + "'  AND  productID ='" + getPara("jyproductIds") + "' and totalExperience >= '"+getPara("jyusage")+"'  ORDER BY totalExperience DESC LIMIT 1");
					CustomerProductSurplus cpsg = CustomerProductSurplus.dao.findFirst("SELECT *   FROM sb_customer_product  WHERE  customerID = '" + cid + "'  AND  productID ='" + getPara("gproductIds") + "' and totalExperience >= '"+getPara("gusage")+"'   ORDER BY totalExperience DESC LIMIT 1");*/
					if(u!=null){
						boolean flag = true;
						if(cpj==null && Float.parseFloat(getPara("jyusage"))>0){
							flag=false;
						}
						if(cpg==null && Float.parseFloat(getPara("gusage"))>0){
							flag=false;
						}
						if(flag){
							if(cpj != null ) {
								Float f = cpj.getFloat("totalexperience") - Float.parseFloat(getPara("jyusage"));
								cpj.set(CustomerProduct.column_totalExperience, f);
								cpj.update();
							}else{
								if(Float.parseFloat(getPara("jyusage"))>0){
									tsy += "精油不够用了，请续产品！";
								}
							
							}
							if(cpg != null) {
								Float f = cpg.getFloat("totalexperience") - Float.parseFloat(getPara("gusage"));
								cpg.set(CustomerProduct.column_totalExperience, f);
								cpg.update();
							}else{
								if(Float.parseFloat(getPara("gusage"))>0){
									tsy += "膏不够用了，请续产品！";
								}
								
							}
							
						}else{
							tsy = "产品不够用了，请续产品！";
						}
						m.put("msg",tsy);
								if((cpg != null||Float.parseFloat(getPara("gusage"))==0)&&(cpj != null)||Float.parseFloat(getPara("jyusage"))==0){
									
									ServiceShaping  ss = ServiceShaping.dao.findFirst("select *  from   sb_customer_service_shaping   where   serviceIds  = ?  ",sid);
									if(ss!=null){
										if (bw.endsWith("yb")) {
											ss.set(ServiceShaping.column_ybjyusage, getPara("jyusage"));
											ss.set(ServiceShaping.column_ybgusage, getPara("gusage"));
											ss.set(ServiceShaping.column_yb, u.getStr("ids"));
										}else  if (bw.endsWith("dt")) {
											ss.set(ServiceShaping.column_dtjyusage, getPara("jyusage"));
											ss.set(ServiceShaping.column_dtgusage, getPara("gusage"));
											ss.set(ServiceShaping.column_dt, u.getStr("ids"));
										}else  if (bw.endsWith("xt")) {
											ss.set(ServiceShaping.column_xtjyusage, getPara("jyusage"));
											ss.set(ServiceShaping.column_xtgusage, getPara("gusage"));
											ss.set(ServiceShaping.column_xt, u.getStr("ids"));
										}else  if (bw.endsWith("gb")) {
											ss.set(ServiceShaping.column_gbjyusage, getPara("jyusage"));
											ss.set(ServiceShaping.column_gbgusage, getPara("gusage"));
											ss.set(ServiceShaping.column_gb, u.getStr("ids"));
										}else  if (bw.endsWith("bb")) {
											ss.set(ServiceShaping.column_bbjyusage, getPara("jyusage"));
											ss.set(ServiceShaping.column_bbgusage, getPara("gusage"));
											ss.set(ServiceShaping.column_bb, u.getStr("ids"));
										}else  if (bw.endsWith("kb")) {
											ss.set(ServiceShaping.column_kbjyusage, getPara("jyusage"));
											ss.set(ServiceShaping.column_kbgusage, getPara("gusage"));
											ss.set(ServiceShaping.column_kb, u.getStr("ids"));
										}else  if (bw.endsWith("zfr")) {
											ss.set(ServiceShaping.column_zfrjyusage, getPara("jyusage"));
											ss.set(ServiceShaping.column_zfrgusage, getPara("gusage"));
											ss.set(ServiceShaping.column_zfr, u.getStr("ids"));
										}else  if (bw.endsWith("yfr")) {
											ss.set(ServiceShaping.column_yfrjyusage, getPara("jyusage"));
											ss.set(ServiceShaping.column_yfrgusage, getPara("gusage"));
											ss.set(ServiceShaping.column_yfr, u.getStr("ids"));
										}
										m.put("msg", ss.update());
									}else{
										ServiceShaping cs1 = new ServiceShaping();
										cs1.set(ServiceShaping.column_customerIds, cid);
										cs1.set(ServiceShaping.column_createDate, dateStr);
										cs1.set(ServiceShaping.column_createId, getCUserIds());
										cs1.set(ServiceShaping.column_organIds, getCUserOrganIds());
										cs1.set(ServiceShaping.column_serviceIds, sid);
										if (bw.endsWith("yb")) {
											cs1.set(ServiceShaping.column_ybjyusage, getPara("jyusage"));
											cs1.set(ServiceShaping.column_ybgusage, getPara("gusage"));
											cs1.set(ServiceShaping.column_yb, u.getStr("ids"));
										}else  if (bw.endsWith("dt")) {
											cs1.set(ServiceShaping.column_dtjyusage, getPara("jyusage"));
											cs1.set(ServiceShaping.column_dtgusage, getPara("gusage"));
											cs1.set(ServiceShaping.column_dt, u.getStr("ids"));
										}else  if (bw.endsWith("xt")) {
											cs1.set(ServiceShaping.column_xtjyusage, getPara("jyusage"));
											cs1.set(ServiceShaping.column_xtgusage, getPara("gusage"));
											cs1.set(ServiceShaping.column_xt, u.getStr("ids"));
										}else  if (bw.endsWith("gb")) {
											cs1.set(ServiceShaping.column_gbjyusage, getPara("jyusage"));
											cs1.set(ServiceShaping.column_gbgusage, getPara("gusage"));
											cs1.set(ServiceShaping.column_gb, u.getStr("ids"));
										}else  if (bw.endsWith("bb")) {
											ss.set(ServiceShaping.column_bbjyusage, getPara("jyusage"));
											ss.set(ServiceShaping.column_bbgusage, getPara("gusage"));
											ss.set(ServiceShaping.column_bb, u.getStr("ids"));
										}else  if (bw.endsWith("kb")) {
											ss.set(ServiceShaping.column_kbjyusage, getPara("jyusage"));
											ss.set(ServiceShaping.column_kbgusage, getPara("gusage"));
											ss.set(ServiceShaping.column_kb, u.getStr("ids"));
										}else  if (bw.endsWith("zfr")) {
											ss.set(ServiceShaping.column_zfrjyusage, getPara("jyusage"));
											ss.set(ServiceShaping.column_zfrgusage, getPara("gusage"));
											ss.set(ServiceShaping.column_zfr, u.getStr("ids"));
										}else  if (bw.endsWith("yfr")) {
											ss.set(ServiceShaping.column_yfrjyusage, getPara("jyusage"));
											ss.set(ServiceShaping.column_yfrgusage, getPara("gusage"));
											ss.set(ServiceShaping.column_yfr, u.getStr("ids"));
										}
										m.put("msg", cs1.save());
									}
									CustomerService cd = CustomerService.dao.findById(sid);
									if(cd !=null){
										cd.set(CustomerService.column_isShaping, "1");
										cd.update();
									}
								}
								
					}else{
						m.put("msg","请选择精护部位人员！"); 
					}
				
				
				}
				
	}
				
				
				
				//------------------------------------------------------
			
			
			
		
			
		/*}else{
			m.put("msg","当天已有服务记录，不能添加！"); 
		}*/
		renderJson(m);
		
		
	}

	public static User updateSerTool(String verificationCode,String orgId) {
		// 1.取用户
		User user = User.dao.findFirst("SELECT * FROM sys_user WHERE verificationCode = ? and organizationids =? and status ='1' ", verificationCode,orgId);
		return user;
	}

	
}
